/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogoIngresoObservacionES.java
 *
 * Created on 03-mar-2013, 18:07:24
 */
package com.camachosanchez.gui;

import com.camachosanchez.util.GUIUtil;

/**
 *
 * @author Rolando
 */
public class DialogoIngresoObservacionES extends javax.swing.JDialog {

    public int OPCION = 0;

    /** Creates new form DialogoIngresoObservacionES */
    public DialogoIngresoObservacionES(java.awt.Frame parent, boolean modal, String comentario, boolean estadoBotonGuardar) {
        super(parent, modal);
        initComponents();
        lblAdvertencia.setVisible(false);
        setSize(350, 200);
        setLocationRelativeTo(null);
        edtComentario.setText(comentario);
        edtComentario.setEditable(estadoBotonGuardar);
        btnGuardar.setEnabled(estadoBotonGuardar);
        GUIUtil.addEscapeKey(this);
    }

    public String getMensaje() {
        return edtComentario.getText().trim();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlOpciones = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        scrComentario = new javax.swing.JScrollPane();
        edtComentario = new javax.swing.JEditorPane();
        lblAdvertencia = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Comentario");
        setResizable(false);

        pnlOpciones.setBackground(new java.awt.Color(231, 239, 247));
        pnlOpciones.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/16_save.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnGuardar.setContentAreaFilled(false);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
        pnlOpciones.add(btnGuardar);

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/16_cancel.png"))); // NOI18N
        btnCancelar.setText("Cerrar");
        btnCancelar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnCancelar.setContentAreaFilled(false);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        pnlOpciones.add(btnCancelar);

        getContentPane().add(pnlOpciones, java.awt.BorderLayout.PAGE_END);

        scrComentario.setViewportView(edtComentario);

        getContentPane().add(scrComentario, java.awt.BorderLayout.CENTER);

        lblAdvertencia.setBackground(new java.awt.Color(231, 239, 247));
        lblAdvertencia.setText("<html><font color='red'>(*) Máximo 80 caracteres</font></html>");
        lblAdvertencia.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4));
        lblAdvertencia.setOpaque(true);
        getContentPane().add(lblAdvertencia, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
// TODO add your handling code here:
    OPCION = 0;
    dispose();
}//GEN-LAST:event_btnCancelarActionPerformed

private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
// TODO add your handling code here:
    if (edtComentario.getText().length() > 79) {
        lblAdvertencia.setVisible(true);
    } else {
        OPCION = 1;
        setVisible(false);
    }
}//GEN-LAST:event_btnGuardarActionPerformed
//    /**
//     * @param args the command line arguments
//     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(DialogoIngresoObservacionES.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(DialogoIngresoObservacionES.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(DialogoIngresoObservacionES.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(DialogoIngresoObservacionES.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the dialog */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                DialogoIngresoObservacionES dialog = new DialogoIngresoObservacionES(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//                    @Override
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JEditorPane edtComentario;
    private javax.swing.JLabel lblAdvertencia;
    private javax.swing.JPanel pnlOpciones;
    private javax.swing.JScrollPane scrComentario;
    // End of variables declaration//GEN-END:variables
}
